package com.ease.business.systemmonitor.job;

import java.util.ArrayList;
import java.util.List;

import com.ease.access.systemmonitor.service.SystemConfAccessService;
import com.ease.access.systemmonitor.service.UnixServerAccessService;
import com.ease.business.systemmonitor.util.ServerInfoUtil;
import com.ease.model.systemmonitor.SystemConf;
import com.ease.model.systemmonitor.UnixServer;

public class GetAllServerInfoTask {

	private SystemConfAccessService systemConfAccessService;

	private UnixServerAccessService unixServerAccessService;

	public SystemConfAccessService getSystemConfAccessService() {
		return systemConfAccessService;
	}

	public void setSystemConfAccessService(SystemConfAccessService systemConfAccessService) {
		this.systemConfAccessService = systemConfAccessService;
	}

	public UnixServerAccessService getUnixServerAccessService() {
		return unixServerAccessService;
	}

	public void setUnixServerAccessService(UnixServerAccessService unixServerAccessService) {
		this.unixServerAccessService = unixServerAccessService;
	}

	public void saveUnixServerInfo() throws Exception {
		// TODO Auto-generated method stub
		// 查找主机列表
		List<SystemConf> listSrv = new ArrayList<SystemConf>();
		listSrv = systemConfAccessService.findAll(null);
		if (listSrv != null)
			for (SystemConf srv : listSrv) {
				UnixServer srvInfo = ServerInfoUtil.getHostPerformance(srv.getIp(), srv.getShUserName(), srv.getShPassWord());
				if (srvInfo != null) {
					srvInfo.setPcid(srv.getId());
					srvInfo.setVersion(1);
					unixServerAccessService.create(srvInfo);
				}

			}

	}

	public void execute() {
		// TODO Auto-generated method stub
		try {
			saveUnixServerInfo();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
